# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator


from jms_hi.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms_hi.dim.dim_lmdm_sys_staff import jms_dim__dim_lmdm_sys_staff
from jms_hi.dim.dim_lmdm_sys_area import jms_dim__dim_lmdm_sys_area
from jms_hi.dim.dim_tmsnew_time_effective_base_hi import jms_dim__dim_tmsnew_time_effective_base_hi
from jms_hi.dim.dim_lmdm_sys_special_time_limit_base import jms_dim__dim_lmdm_sys_special_time_limit_base
from jms_hi.dwd.tab.dwd_tab_barscan_sitesend_base_hi import jms_dwd__dwd_tab_barscan_sitesend_base_hi
from jms_hi.dwd.tab.dwd_tab_reback_transfer_express_base_hi import jms_dwd__dwd_tab_reback_transfer_express_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_send_base_hi import jms_dwd__dwd_tab_barscan_send_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_collect_base_hi import jms_dwd__dwd_tab_barscan_collect_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_sitearrival_base_hi import jms_dwd__dwd_tab_barscan_sitearrival_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_deliver_base_hi import jms_dwd__dwd_tab_barscan_deliver_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_sign_base_hi import jms_dwd__dwd_tab_barscan_sign_base_hi
from jms_hi.dwd.other.dwd_yl_sms_send_detail_base_hi import jms_dwd__dwd_yl_sms_send_detail_base_hi

jms_dm__dm_reback_transfer_warming_waybill_detail_dt = SparkSqlOperator(
    task_id='jms_dm__dm_reback_transfer_warming_waybill_detail_dt',
    task_concurrency=1,
    pool_slots=3,
    master='yarn',
    execution_timeout=timedelta(hours=1),
    depends_on_past=True,
    email=['jimmyk.ji@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_reback_transfer_warming_waybill_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',  # yarn 任务名称
    sql='jms_hi/dm/dm_reback_transfer_warming_waybill_detail_dt/execute.hql',
    driver_memory='8G',
    driver_cores=2,
    executor_memory='16G',
    executor_cores=4,
    num_executors=50,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 50 ,
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 300,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.executor.memoryOverhead'             : '2G' ,
        'spark.hadoop.hive.exec.dynamic.partition.mode': 'nonstrict', # 动态分区
        'spark.hadoop.hive.exec.dynamic.partition': 'true',
        'spark.default.parallelism': 600,
        'spark.sql.shuffle.partitions': 1200,
        'spark.core.connection.ack.wait.timeout': 300,
        'spark.locality.wait': 120,
    },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200
              },
    yarn_queue='pro',
)

# 设置依赖
jms_dm__dm_reback_transfer_warming_waybill_detail_dt << [
    jms_dim__dim_network_whole_massage,
    jms_dim__dim_lmdm_sys_staff,
    jms_dim__dim_lmdm_sys_area,
    jms_dim__dim_lmdm_sys_special_time_limit_base,
    jms_dwd__dwd_tab_barscan_sitesend_base_hi,
    jms_dwd__dwd_tab_reback_transfer_express_base_hi,
    jms_dwd__dwd_tab_barscan_send_base_hi,
    jms_dwd__dwd_tab_barscan_collect_base_hi,
    jms_dwd__dwd_tab_barscan_sitearrival_base_hi,
    jms_dwd__dwd_tab_barscan_deliver_base_hi,
    jms_dwd__dwd_tab_barscan_sign_base_hi,
    jms_dim__dim_tmsnew_time_effective_base_hi,
    jms_dwd__dwd_yl_sms_send_detail_base_hi
]


